<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<head>
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/style/gen-style.css"
	type="text/css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/style/mkv/jquery-ui.css"
	type="text/css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/style/makovo-style.css"
	type="text/css" />
<link rel="stylesheet"
	href="<%=request.getContextPath()%>/style/jquery.steps.css"
	type="text/css" />

<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/jquery-2.1.3.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/gen.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/inegi.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/jquery-ui-1.9.2.custom.min.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/spin.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/jquery.steps.min.js"></script>
<script type="text/javascript"
	src="<%=request.getContextPath()%>/scripts/auxiliares.js"></script>
<script type="text/javascript">
	var mVal = new Gen.Validator('val');
	var mUIHelper = new Gen.UIHelper();
	var mCall = new Gen.AjaxCall();

	$(document).ready(function() {

		if (validaSesion("${sessionScope.LoginMenu}"))
			document.location = "index.jsp";
		var form = $('#ProjectRegister').show();

		form.steps({
			headerTag : "h3",
			bodyTag : "fieldset",
			transitionEffect : "slideLeft",
			showFinishButtonAlways : false,
			enableFinishButton : false
		});

		$('[name=stateId]').change(function() {
			var stateId = $(this).val();
			var state = findValue(Inegi.states, 'id', stateId);
			$('[name=locId]').find('option').remove();
			$('[name=locId]').append($('<option value="-1">... Seleccione una opción ...</option>'))
			$('[name=lonng]').val("");
			$('[name=lat]').val("");

			$('[name=state]').val(state.name);

			Inegi.fillCities($('[name=cityId]'), stateId, true);
		});

		$('[name=cityId]').change(function() {
			var cityId = $(this).val();
			Inegi.fillTowns($('[name=locId]'), $('[name=stateId]').val(), cityId, true);

			var selCity = findValue(Inegi.cities, 'clave_municipio', cityId);

			$('[name=city]').val(selCity.nombre_municipio);
			$('[name=lonng]').val(selCity.lng);
			$('[name=lat]').val(selCity.lat);
		});

		$('[name=locId]').change(function() {
			var locId = $(this).val();

			$('[name=loc]').val($('[name=locId] :selected').text());
		});

		$('[name=sameAddress]').change(function() {

			if ($(this).is(':checked')) {
				$('.dis').not('.lock').attr('disabled', 'disabled');
				getAddress();
			} else {
				$('.dis:text').val("");
				$('.dis').not('.lock').removeAttr('disabled');
				$('.dis').not('.lock').filter('select').val("-1")
				setFields("${sessionScope.LogintipoUsr}")
			}

		});

		function setFields(userType) {
			if (userType == "4") {
				showOverlay(true);
				$('.lock').attr('disabled', 'disabled')
				getUserInfo()
			} else
				$('.lock').removeClass('lock')

		}

		function getUserInfo() {
			new Gen.AjaxCall().post('ajax/GetUserInfo.action', {}, function(a) {
				if (a != null) {
					$('[name=stateId]').val(a.idState)
					$('[name=state]').val(findValue(Inegi.states, "id", 28).name)

					Inegi.fillCities($('[name=cityId]'), a.idState, false, function() {
						hideOverlay();
						$('[name=cityId]').val(a.idCity);
						$('[name=city]').val($('[name=cityId] :selected').text());

						Inegi.fillTowns($('[name=locId]'), a.idState, a.idCity, true);
					});

				}

			}, function(er) {
				hideOverlay();
			});
		}

		Inegi.fillStates($('[name=stateId]'));

		setFields("${sessionScope.LogintipoUsr}")
	});

	function getAddress() {
		showOverlay(true);

		mCall.post('ajax/GetApplicantInfo.action', {}, function(a) {
			a = a.address;

			$('[name=street]').val(a.street);
			$('[name=extNumber]').val(a.extNum);
			$('[name=intNumber]').val(a.intNum);
			$('[name=lonng]').val(a.lonng);
			$('[name=lat]').val(a.lat);
			$('[name=cp]').val(a.cp);
			$('[name=col]').val(a.col);
			$('[name=stateId]').val(a.stateId);

			var city = [];
			city.push({
				id : a.cityId,
				state : a.city
			});

			var loc = [];
			loc.push({
				id : a.locId,
				loc : a.loc
			});

			mUIHelper.fillCombo(city, $('[name=cityId]'), "id", "state", true, false);
			mUIHelper.fillCombo(loc, $('[name=locId]'), "id", "loc", true, false);

			hideOverlay();
		}, function(er) {
			hideOverlay();
		});
	}

	function validate() {
		var errors = mVal.validate($('[name=ProjectRegister]'), function() {
		});

		if (errors.length != 0) {
			$('#ProjectRegister').steps('previous');
			$('#ProjectRegister').steps('previous');

		}

		if (errors.length == 0)
			$('.lock').removeAttr('disabled');

		return errors.length == 0;
	}
</script>

</head>
<body>
	<div style="width: 1100px; margin: 0 auto">
		<div class="headerMK">
			<div class="logo">
				<span class="hdTitulo">Sistema para Aplicación de Subsidio
					2015</span>
			</div>
			<div
				style="font-size: 0.26em; top: -50px; position: relative; width: 500px; float: right; text-align: right; padding-right: 10px">
				<i>${sessionScope.LoginNombre}</i><b><a
					href="/makovo/paginas/index.jsp"> - Cerrar Sesión</a></b>
			</div>
		</div>
		<div class="divContenido">
			<a href="<%=request.getContextPath()%>/paginas/menu.jsp">Regresar
				al menú</a> <br /> <br />

			<h3>Registro de información de proyecto</h3>


			<div style="width: 1000px; margin: 0px auto; padding: 2em;">
				<s:form action="ProjectRegister">
					<h3>Datos del proyecto</h3>
					<fieldset>
						<div style="width: 100%; float: left; padding-top: 10px">
							<div style="float: left">
								Folio del proyecto:
								<s:textfield name="projId" theme="simple" cssClass="inputText"
									val="text-spaces" maxlength="15" />
							</div>
							<div style="float: left; padding-left: 10px">
								Tipo de proyecto:<br />
								<s:select theme="simple"
									list="#{'1':'Recámara adicional','2':'Unidad básica de vivienda', '3':'Remodelación', '4':'Lote con servicios'}"
									name="projType" cssClass="inputSelect" />
							</div>
							<div style="float: left; padding-left: 10px">
								Tipo de asentamiento:<br />
								<s:select theme="simple"
									list="#{'1':'Urbano','2':'Rural', '3':'SubUrbano'}"
									name="projSett" cssClass="inputSelect" />
							</div>
							<br /> <br /> <br />

							<s:if test="hasActionErrors()">
								<div class="server-error">
									<span class="server-error-title">Verifique los
										siguientes campos:</span><br />
									<s:actionerror />
								</div>
							</s:if>
						</div>
					</fieldset>
					<h3>Domicilio Proyecto</h3>
					<fieldset>
						<div style="width: 100%; float: left; padding-top: 10px">
							<div style="float: left">
								<s:checkbox name="sameAddress" fieldValue="true" value="false"
									theme="simple" />
								Utilizar la misma dirección del aplicante
							</div>
						</div>
						<div style="width: 100%; float: left; padding-top: 10px">
							<div style="float: left">
								Calle:
								<s:textfield name="street" style="width:300px" theme="simple"
									cssClass="inputText dis" val="text-spaces" maxlength="45" />
							</div>
							<div style="float: left; padding-left: 10px">
								Número externo:
								<s:textfield name="extNumber" theme="simple"
									cssClass="inputText dis" val="text-spaces" maxlength="10" />
							</div>
							<div style="float: left; padding-left: 10px">
								Número interno:
								<s:textfield name="intNumber" theme="simple"
									cssClass="inputText dis" val="text-spaces" maxlength="10" />
							</div>
							<div style="float: left; padding-left: 10px">
								Colonia:
								<s:textfield name="col" theme="simple"
									cssClass="inputText dis" val="text-spaces" maxlength="30" />
							</div>
						</div>
						<div style="width: 100%; float: left; padding-top: 10px">
							<div style="float: left">
								Estado:<br />
								<s:select theme="simple" list="#{'1':'Mostrar estados'}"
									name="stateId" cssClass="inputSelect dis lock" val="selected"
									wrongOption="-1" />
								<s:hidden name="state" value="-1" />
							</div>
							<div style="float: left; padding-left: 10px">
								Ciudad:<br />
								<s:select theme="simple" list="#{'1':'Mostrar estados'}"
									name="cityId" cssClass="inputSelect dis lock" val="selected"
									wrongOption="-1" />
								<s:hidden name="city" value="-1" />
							</div>
							<div style="float: left; padding-left: 10px">
								Localidad:<br />
								<s:select theme="simple" list="#{'1':'Mostrar estados'}"
									name="locId" cssClass="inputSelect dis" val="selected"
									wrongOption="-1" />
								<s:hidden name="loc" value="-1" />
							</div>
						</div>
						<div style="width: 100%; float: left; padding-top: 10px">
							<div style="float: left">
								Longitud:
								<s:textfield name="lonng" theme="simple"
									cssClass="inputText dis" readonly="true" maxlength="10" />
							</div>
							<div style="float: left; padding-left: 10px">
								Latitud:
								<s:textfield name="lat" theme="simple" cssClass="inputText dis"
									readonly="true" maxlength="10" />
							</div>
							<div style="float: left; padding-left: 10px">
								Código postal:
								<s:textfield name="cp" theme="simple" cssClass="inputText dis"
									val="just-numbers" maxlength="7" />
							</div>
						</div>
						<div style="width: 100%; float: left; padding-top: 10px">
							<div style="float: left">
								Entre calles:
								<s:textfield name="refOne" theme="simple" cssClass="inputText"
									val="text-spaces" maxlength="50" />
							</div>
							<div style="float: left; padding-left: 10px">
								<br />
								<s:textfield name="refTwo" theme="simple" cssClass="inputText"
									val="text-spaces" maxlength="50" />
							</div>
							<div style="float: left; padding-left: 10px">
								Tipo de vialidad:<br />
								<s:select theme="simple"
									list="#{'1':'Calle', '2':'Avenida', '3':'Autopista' }"
									name="vialType" cssClass="inputSelect" />
							</div>
						</div>

					</fieldset>
					<h3>Finalizar</h3>
					<fieldset>
						<s:submit value="Generar registro" theme="simple"
							cssClass="class java.util.HashMap t-btn tinny change"
							onclick="if (!validate()) return false;" />
					</fieldset>

				</s:form>
			</div>
		</div>
	</div>
</body>
</html>